﻿CREATE FUNCTION [dbo].[fn_AllPad](@text [varchar](128), @PADtext [char](1), @PADlimit [int], @PADType [char](1))
RETURNS [varchar](512) WITH EXECUTE AS CALLER
AS 
begin
declare @resultPAD varchar(512)
set @resultPAD =''
--Left Padding
If @PADtype ='L' 
begin
set @resultPAD =right(replicate(@PADtext,@PADlimit)+@text,@PADlimit)
end
--Right Padding
If @PADtype ='R' 
begin
set @resultPAD =left(@text+replicate(@PADtext,@PADlimit),@PADlimit)
end
--No Padding
If @PADtype not in ('R' , 'L' )
begin
set @resultPAD = NULL
end	
return @resultPAD
end


